package com.seven.system.controller.api;

import com.seven.annotation.AuthAnnotation;
import com.seven.enity.Permission;
import com.seven.system.service.PermissionService;
import com.seven.utils.JWTUtil;
import com.seven.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author longlong
 * @date 2024/3/6 15:57
 * description
 */
@RestController
@RequestMapping("/system/permission")
public class PermissionController {
    @Resource
    private PermissionService permissionService;

    @GetMapping("/getByUserId/{userId}")
    public List<Permission> getByUserId(@PathVariable String userId){
        return permissionService.getPermissionListByUserId(userId);
    }

    @GetMapping("/leftMenu")
    public Result getLeftMenuByUserName(HttpServletRequest request){
        //1获取用户姓名
        String token = request.getHeader("token");
        String username = JWTUtil.parseToken(token);
//        2.查询用户拥有的权限菜单
        List<Permission> permissions = permissionService.getLeftMenuByUserName(username);
        return new Result(2000,"查询成功",permissions);

    }






}
